home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / wmlib / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-29  |  2.3 KB  |  96 lines

  1. /* event.c - WindowMaker event handler
  2.  * 
  3.  * WMlib - WindowMaker application programming interface
  4.  * 
  5.  * Copyright (C) 1997 Alfredo K. Kojima
  6.  *  
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Library General Public
  9.  *  License as published by the Free Software Foundation; either
  10.  *  version 2 of the License, or (at your option) any later version.
  11.  *  
  12.  *  This library is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  *  Library General Public License for more details.
  16.  *  
  17.  *  You should have received a copy of the GNU Library General Public
  18.  *  License along with this library; if not, write to the Free
  19.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26.  
  27. #include "WMaker.h"
  28. #include "app.h"
  29. #include "menu.h"
  30.  
  31.  
  32. static Atom _XA_WINDOWMAKER_MENU=0;
  33.  
  34. enum {
  35.     wmSelectItem = 1
  36. };
  37.  
  38.  
  39. static wmMenuEntry*
  40. findEntry(WMMenu *menu, int tag)
  41. {
  42.     wmMenuEntry *entry=menu->first;
  43.  
  44.     while (entry) {
  45.     if (entry->tag == tag) {
  46.         return entry;
  47.     }
  48.     if (entry->cascade) {
  49.         wmMenuEntry *tmp;
  50.         tmp = findEntry(entry->cascade, tag);
  51.         if (tmp)
  52.           return tmp;
  53.     }
  54.     entry = entry->next;
  55.     }
  56.     return NULL;
  57. }
  58.  
  59.  
  60. static void
  61. wmHandleMenuEvents(WMAppContext *app, XEvent *event)
  62. {
  63.     wmMenuEntry *entry;
  64.  
  65.     switch (event->xclient.data.l[1]) {
  66.      case wmSelectItem:
  67.     entry = findEntry(app->main_menu, event->xclient.data.l[2]);
  68.     if (entry && entry->callback) {
  69.         (*entry->callback)(entry->clientData, event->xclient.data.l[2],
  70.                    event->xclient.data.l[0]);
  71.     }
  72.     break;
  73.     }
  74. }
  75.  
  76.  
  77. int
  78. WMProcessEvent(WMAppContext *app, XEvent *event)
  79. {
  80.     int proc=False;
  81.     if (!_XA_WINDOWMAKER_MENU) {
  82.     _XA_WINDOWMAKER_MENU = XInternAtom(app->dpy, "_WINDOWMAKER_MENU", 
  83.                        False);
  84.     }
  85.     switch (event->type) {
  86.      case ClientMessage:
  87.     if (event->xclient.format == 32
  88.         && event->xclient.message_type == _XA_WINDOWMAKER_MENU
  89.         && event->xclient.window == app->main_window) {
  90.         wmHandleMenuEvents(app, event);
  91.         proc = True;
  92.     }
  93.     }
  94.     return proc;
  95. }
  96.